home *** CD-ROM | disk | FTP | other *** search
/ MacTech 1 to 12 / MacTech-vol-1-12.toast / Source / MacTech® Magazine / Volume 09 - 1993 / 09.04 Apr 93 / Creating EPSF Files / PSDbits.c < prev    next >
Encoding:
Text File  |  1992-07-15  |  2.5 KB  |  77 lines  |  [TEXT/KAHL]

  1. /* PSDbits.c */
  2. /* This module contains the routines for bitmap operations */
  3. /* Copyright 1992, Gary D. McGath */
  4.  
  5. pascal void psdBitsProc(BitMap *srcBits, Rect *srcRect, Rect *dstRect,
  6.             short mode, RgnHandle maskRgn);
  7.  
  8. extern int thePSFile;            /* ID of file to output to */
  9.  
  10.  
  11.  
  12. /* In this version, the only mode supported is copy. Most others
  13.    are problematical, since PostScript doesn't allow logical combinations
  14.    with an existing raster.
  15.    We support only 1-bit bitmaps here; Pixmaps are ignored (left as an
  16.    exercise for the reader). */
  17. pascal void psdBitsProc(BitMap *srcBits, Rect *srcRect, Rect *dstRect,
  18.             short mode, RgnHandle maskRgn)
  19. {
  20.     int pixelWidth, pixelDepth;
  21.     Ptr dataPtr;
  22.     int byteWidth;
  23.     register int i, j;
  24.     
  25.     if (srcBits->rowBytes & 0X8000)            /* is it a pixmap? */
  26.         return;                                /* then give up */
  27.     if (srcRect->left != srcBits->bounds.left)
  28.         return;                                /* we don't handle this case properly yet */
  29.  
  30.     pixelWidth = srcRect->right - srcRect->left;
  31.     pixelDepth = srcRect->bottom - srcRect->top;
  32.     byteWidth = (pixelWidth + 7) / 8;
  33.  
  34.     OutputString("/SV save def /ims ",thePSFile);    /* avoid accumulating garbage */
  35.     OutputNum(byteWidth,thePSFile);
  36.     OutputString("string def\r",thePSFile);            /* buffer 1 scan line wide */
  37.     /* First need to scale and position to target rect */
  38.     OutputNum(dstRect->left, thePSFile);
  39.     OutputNum(dstRect->top, thePSFile);
  40.     OutputString("translate\r",thePSFile);
  41.     
  42.     OutputNum(dstRect->right - dstRect->left, thePSFile);
  43.     OutputNum(dstRect->bottom - dstRect->top, thePSFile);
  44.     OutputString("scale\r",thePSFile);
  45.     
  46.     
  47.     /* Output "w h 1 [w 0 0 h 0 0 ] {currentfile ims readhexstring pop} image" */
  48.     
  49.     OutputNum(pixelWidth, thePSFile);
  50.     OutputNum(pixelDepth, thePSFile);
  51.     OutputString("1 [",thePSFile);
  52.     OutputNum(pixelWidth, thePSFile);    /* width */
  53.     OutputString("0 0 ", thePSFile);
  54.     OutputNum(pixelDepth, thePSFile);
  55.     OutputString("0 0 ] {currentfile ims readhexstring pop} image\r",thePSFile);
  56.  
  57.     /* Now output the image as hex data. As a further cheap trick, we
  58.        assume that the left edge of srcRect matches the left edge of the
  59.        BitMap rectangle; in real life this isn't a valid assumption,
  60.        and bit shifting will be needed. */
  61.     dataPtr = srcBits->baseAddr;
  62.     for (i = 0; i < pixelDepth; i++) {
  63.         for (j = 0; j < byteWidth; j++) {
  64.             OutputHex(~*dataPtr++,thePSFile);
  65.             if ((j & 0X7F) == 0X7F)
  66.                 OutputChar('\r', thePSFile);    /* avoid excessively long lines */
  67.         }
  68.         if (byteWidth & 1)                /* if odd, have to skip a byte at end of row */
  69.             dataPtr++;
  70.         OutputChar('\r', thePSFile);
  71.     }
  72.     OutputString("SV restore\r",thePSFile);
  73. }
  74.  
  75.  
  76.  
  77.